#pragma  once

#include "tlistdlg.h"
#include "msgmng.h"
#include "LogMng.h"
#include "SHARE.h"
#include "cfg.h"

class TSendDlg : public TListDlg {
protected:
	MsgMng		*msgMng;
	Cfg			*cfg;
	LogMng		*logmng;
	HWND		hRecvWnd;
	MsgBuf		msg;
	ShareMng	*shareMng;
	ShareInfo	*shareInfo;

	THosts		*hosts;
	TFindDlg	*findDlg;
	Host		**hostArray;
	int			memberCnt;

	SendEntry	*sendEntry;
	int			sendEntryNum;
	UINT		command;
	char		*shareStr;
	char		msgBuf[MAX_UDPBUF];
	char		selectGroup[MAX_NAMEBUF];

	ULONG		packetNo;
	int			packetLen;
	UINT		timerID;
	UINT		retryCnt;

	// display
	HFONT		hListFont;
	HFONT		hEditFont;
	LOGFONT		orgFont;

	RECT		orgRect;
	enum		send_item { host_item=0, member_item, refresh_item, edit_item, ok_item, secret_item, passwd_item, separate_item, file_item,groupselect_item, max_senditem };
	WINPOS		item[max_senditem];

	int			currentMidYdiff;
	int			dividYPos;
	int			lastYPos;
	BOOL		captureMode;
	BOOL		listOperateCnt;
	BOOL		hiddenDisp;

	int			maxItems;
	UINT		ColumnItems;
	int			FullOrder[MAX_SENDWIDTH];
	int			items[MAX_SENDWIDTH];
	BOOL		lvStateEnable;
	int			sortItem;
	BOOL		sortRev;

	TEditSub		editSub;
	TListViewEx		hostListView;
	TSeparateSub	separateSub;

	void	SetFont(void);
	void	SetSize(void);
	void	SetMainMenu(HMENU hMenu);
	void	PopupContextMenu(POINTS pos);
	//added by wallimn
	void	PopupGroupSelect(POINTS pos);
	void	GetOrder(void);

	void	SetQuoteStr(LPSTR str, LPCSTR quoteStr);
	void	SelectHost(HostSub *hostSub, BOOL force=FALSE);
	void	DisplayMemberCnt(void);
	UINT	GetInsertIndexPoint(Host *host);
	int		CompareHosts(Host *host1, Host *host2);
	int		GroupCompare(Host *host1, Host *host2);
	int		SubCompare(Host *host1, Host *host2);
	BOOL	SendMsg(void);
	BOOL	SendMsgSub(void);
	BOOL	MakeEncryptPacket(SendEntry *entry);
	BOOL	MakeEncryptMsg(Host *host, char *msgstr, char *buf);
	BOOL	IsSendFinish(void);
	void	InitializeHeader(void);
	char	*GetListItemStr(Host *host, int item);
	void	MakeEncryptMsg(Host *host, char *msgbuf);

public:
	TSendDlg(MsgMng *_msgmng, ShareMng *_shareMng, THosts *_hosts, Cfg *cfg, LogMng *logmng, HWND _hRecvWnd = NULL, MsgBuf *msg = NULL);
	virtual ~TSendDlg();

	HWND	GetRecvWnd(void) { return	hRecvWnd; }
	void	AddHost(Host *host);
	void	ModifyHost(Host *host);
	void	DelHost(Host *host);
	void	DelAllHost(void);
	BOOL	IsSending(void);
	BOOL	SendFinishNotify(HostSub *hostSub, ULONG packet_no);
	BOOL	SendPubKeyNotify(HostSub *hostSub, BYTE *pubkey, int len, int e, int capa);
	BOOL	FindHost(char *findStr, BOOL isAllfind);

	virtual BOOL	EvCreate(LPARAM lParam);
	virtual BOOL	EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl);
	virtual BOOL	EvSysCommand(WPARAM uCmdType, POINTS pos);
	virtual BOOL	EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight);
	virtual BOOL	EvTimer(WPARAM timerID, TIMERPROC proc);
	virtual BOOL	EvGetMinMaxInfo(MINMAXINFO *info);
	virtual BOOL	EvMouseMove(UINT fwKeys, POINTS pos);
	virtual BOOL	EvContextMenu(HWND childWnd, POINTS pos);
	virtual BOOL	EvMeasureItem(UINT ctlID, MEASUREITEMSTRUCT *lpMis);
	virtual BOOL	EvDrawItem(UINT ctlID, DRAWITEMSTRUCT *lpDis);

	virtual BOOL	EvMenuSelect(UINT uItem, UINT fuFlag, HMENU hMenu);
	virtual BOOL	EvNotify(UINT ctlID, NMHDR *pNmHdr);
	virtual BOOL	EvDropFiles(HDROP hDrop);
	virtual BOOL	EventButton(UINT uMsg, int nHitTest, POINTS pos);
	virtual BOOL	EventInitMenu(UINT uMsg, HMENU hMenu, UINT uPos, BOOL fSystemMenu);
	virtual BOOL	EventCtlColor(UINT uMsg, HDC hDcCtl, HWND hWndCtl, HBRUSH *result);
	virtual BOOL	EventUser(UINT uMsg, WPARAM wParam, LPARAM lParam);
	virtual void	Show(int mode = SW_SHOWDEFAULT);
};
